package com.example.appiumautotest;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.util.ReflectionUtils;

import java.lang.reflect.Method;
import java.util.concurrent.TimeUnit;

@Slf4j
@SpringBootApplication
public class AppiumAutoTestApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext run = SpringApplication.run(AppiumAutoTestApplication.class, args);

        // 开启调用
        Object startMain = run.getBeanFactory().getBean("startMain");
        // 利用反射执行自己的方法
        Method start = ReflectionUtils.findMethod(startMain.getClass(), "start");
        Object o = ReflectionUtils.invokeMethod(start,startMain);

        int second = 3;
        log.info("执行完毕,即将在{}秒后关闭程序！",second);

        // 执行完毕后，主动关闭项目
        try {TimeUnit.SECONDS.sleep(second);}
        catch (InterruptedException e) {throw new RuntimeException(e);}
        run.close();
    }

}
